package com.taropan.wallpaper.util;

import java.util.ArrayList;
import java.util.List;

import com.taropan.wallpaper.ui.BaseActivity;

import android.app.Activity;

/**
 * 
 * @author taro
 *
 */
public class ActivityManager {

    private static List<Activity> activities = new ArrayList<Activity>();

    public static synchronized void addActivity(Activity activity) {
        activities.add(activity);
    }

    public static synchronized void removeActivity(Activity activity) {
        activities.remove(activity);
    }

    public static final synchronized List<Activity> getActivities() {
        return activities;
    }

    public static synchronized void finishAll() {
    	try {
    		for (Activity activity : activities) {
                if (!(activity.isChild() || activity.isFinishing()))
                    ((BaseActivity) activity).finishAll();
            }
            activities.clear();
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
}
